//
//  Demo927ViewController.m
//  Demo927
//
//  Created by qianfeng on 11-9-27.
//  Copyright __MyCompanyName__ 2011. All rights reserved.
//

#import "Demo927ViewController.h"

@implementation Demo927ViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/




@synthesize bookLabel;


- (void)viewDidLoad {
    [super viewDidLoad];
	
	NSString *s = @"千锋IOS课程第二个星期";
	UIFont *font = [UIFont fontWithName:@"Arial" size:40.0f];
	
	CGRect rect = CGRectZero;
	// == CGRectMake(0, 0, 0, 0);
	UILabel *label2 = [[UILabel alloc] initWithFrame:rect];
	label2.numberOfLines = 0;
	
	float w = [[UIScreen mainScreen] applicationFrame].size.width;
	float h = [[UIScreen mainScreen] applicationFrame].size.height;
	/*得到整个屏幕的对象 UIScreen mainScreen
	  applicationFrame表示应用程序的框架frame*/
	
	CGSize size = CGSizeMake(w, h);
	CGSize labelSize = [s sizeWithFont:font
						constrainedToSize:size
						lineBreakMode:UILineBreakModeWordWrap];
	NSLog(@"label width %d height %d", labelSize.width, labelSize.height);
	
	label2.frame = CGRectMake(0, 0, labelSize.width, labelSize.height);
	/*frame的意思是label的原点坐标和宽高*/
	label2.textColor = [UIColor redColor];
	label2.backgroundColor = [UIColor clearColor];
	label2.font = font;
	label2.text = s;
	[self.view addSubview:label2];
	
	self.bookLabel = label2;
	
	[label2 release];

	UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	button1.frame = CGRectMake(275, 100, 45, 45);
	[button1 setTitle:@"上" forState:UIControlStateNormal];
	[button1 
		addTarget:self
		action:@selector(prevPage:)
		forControlEvents:UIControlEventTouchUpInside];
	/*意思是当button1 有UIControlEventTouchUpInside事件时,系统加会调用[self prevPage:]方法
	 @selector这个是oc的语法,意思就是把后面的prevPage:方法转成一个函数指针*/
	button1.alpha = 0.5f;
	[self.view addSubview:button1];
	
	UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	button2.frame = CGRectMake(275, 300, 45, 45);
	[button2 setTitle:@"下" forState:UIControlStateNormal];
	[button2
		addTarget:self 
		action:@selector(nextPage:) 
		forControlEvents:UIControlEventTouchUpInside];
	button2.alpha = 0.5f;
	[self.view addSubview:button2];
	
	
}


- (IBAction) nextPage:(id)sender{
	NSString *s = @"下一页的内容为";
	UIFont *font = [UIFont fontWithName:@"Arial" size:40.0f];
	CGSize size = CGSizeMake(320, 460);
	
	CGSize labelSize = [s sizeWithFont:font
					 constrainedToSize:size
						 lineBreakMode:UILineBreakModeWordWrap];
	self.bookLabel.frame = CGRectMake(0, 0, labelSize.width, labelSize.height);
	self.bookLabel.font = font;
	self.bookLabel.text = s;
	
	NSLog(@"%d : %d", labelSize.width, labelSize.height);
}

- (IBAction) prevPage:(id)sender{
	NSString *s = @"上一页的内容为";
	UIFont *font = [UIFont fontWithName:@"Arial" size:40.0f];
	CGSize size = CGSizeMake(320, 460);
	
	CGSize labelSize = [s sizeWithFont:font
					 constrainedToSize:size
						 lineBreakMode:UILineBreakModeWordWrap];
	self.bookLabel.frame = CGRectMake(0, 0, labelSize.width, labelSize.height);
	self.bookLabel.font = font;
	self.bookLabel.text = s;
}


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad2 {
    [super viewDidLoad];
	
	CGRect rect = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
	UILabel *myLabel = [[UILabel alloc] initWithFrame:rect];
	//UILabel alloc的作用是分配一个UILabel的内存空间
	
	myLabel.text = @"千锋IOS a aa aaa aaaa aaaaa";
	myLabel.lineBreakMode = UILineBreakModeWordWrap;
	//折行模式
	myLabel.numberOfLines = 10;
	//一共有几行
	myLabel.backgroundColor = [UIColor clearColor];
	//表示标签的背景颜色,redcolor表示红色
	myLabel.textColor = [UIColor redColor];
	myLabel.font = [UIFont fontWithName:@"Arial" size:40.0f];
	
	[self.view addSubview:myLabel];
	/*意思就是把myLabel加到view中去
	 放在view的位置是由mylabel决定的,位置是(0,0,100,40)
	 
	[myLabel release];
	
}*/
//这个函数意思就是xib文件加载完成要做的额外的事情


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	self.bookLabel = nil;
    [super dealloc];
}

@end
